<template>
  <div>
    <el-dialog
      title="新增"
      :visible="isShowAddDialog"
      width="35%"
      @close="dialogClose"
    >
      <el-form
        ref="addForm"
        :model="ruleForm"
        :rules="rules"
        label-width="auto"
      >
        <el-form-item label="分组名称" prop="name">
          <el-input v-model="ruleForm.name" placeholder="分组名称"></el-input>
        </el-form-item>
        <el-form-item label="业务类型" prop="ywlx">
          <el-select v-model="ruleForm.ywlx">
            <el-option
              v-for="item in YwTypeOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="常用语类型" prop="cyylx">
          <el-select v-model="ruleForm.cyylx">
            <el-option
              v-for="item in CyyTypeOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            @click="submitData()"
            class="pull-right margin-l-25"
            >确定
          </el-button>
          <el-button @click="dialogClose" class="pull-right">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { addCyyfz } from "@/api/evaluation/word";
import { findByName } from "@/api/systemManage/dataDictionary";
export default {
  //接受父组件
  props: {
    isShowAddDialog: {
      type: Boolean,
    },
  },

  data() {
    return {
      YwTypeOptions: [],
      CyyTypeOptions: [],
      ruleForm: {
        name: "",
        ywlx: "",
        cyylx: "",
      },
      rules: {
        name: [
          {
            required: true,
            message: "请输入分组名称",
            trigger: "blur",
          },
        ],
        ywlx: [
          {
            required: true,
            message: "请选择业务类型",
            trigger: "blur",
          },
        ],
        cyylx: [
          {
            required: true,
            message: "请选择常用语类型",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    dialogClose() {
      this.$emit("dialogClose");
    },
    submitData() {
      this.$refs.addForm.validate((valid) => {
        if (!valid) {
          return;
        } else {
          this.ruleForm.companyId = 3;
          addCyyfz(this.ruleForm).then((res) => {
            this.$emit("close");
            this.$emit("dialogClose");
          });
        }
      });
    },
    getOption() {
      findByName("input=" + "常用语类型").then((res) => {
        for (var i = 0; i < res.data.length; i++) {
          if(res.data[i].dictName=='常用语类型')
          this.CyyTypeOptions.push({
            label: res.data[i].dictValue,
            value: res.data[i].dictValue,
          });
        }
      });
    },
    getOption1() {
      findByName("input=" + "业务类型").then((res) => {
        for (var i = 0; i < res.data.length; i++) {
          if(res.data[i].dictName=='业务类型')
          this.YwTypeOptions.push({
            label: res.data[i].dictValue,
            value: res.data[i].dictValue,
          });
        }
      });
    },
  },
  mounted() {
    this.getOption();
    this.getOption1();
  },
};
</script>

<style lang="less" scoped></style>
